#pragma once

#include <engine.video/Device.hpp>
#include <engine.input/Device.hpp>

#include "exports.hpp"
#include "Component.hpp"
#include "PositionComponent.hpp"




namespace Engine
{
	namespace Entity
	{
		class CameraComponent
			: public Component
		{
		public:

			typedef Script::pointer<CameraComponent>   ptr;

			CameraComponent(Input::Device::ptr inputDevice, Video::Device::ptr videoDevice);
			virtual ~CameraComponent();



			/**
			 * @returns the id of this component type
			 */
			ID id() const;

			/**
			 * @returns the ids of all components this component requires
			 */
			IDs requiredComponents() const;



			/**
			 * Is called when this component is attached to an entity.
			 */
			virtual void attached(Entity::Object* entity, const map& components);

			/**
			 * Is called when this component is detached from an entity.
			 */
			virtual void detached(Entity::Object* entity);


			/**
			 * Updates this component
			 */
			void update();



			/**
			 * Registers the script system type with angelscript.
			 */
			static void registerType(Script::System::ptr engine);

		private:

			Input::Device::ptr       m_inputDevice;
			Video::Camera*           m_camera;
			PositionComponent::ptr   m_lookAt;

			// Spherical coordinates in order to calculate the target
			units::angle<float>      m_latitude;
			units::angle<float>      m_longitude;
			units::length<float>     m_radius;

			float3                   m_targetCameraPosition;

			float3                   m_cameraPosition;
			float3                   m_cameraLookAt;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
